﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Zijian666;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Ccli.BindCli(new Cli(this));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Console.SetOut(new MyWirter());
            Ccli.OpenConsole(8037);
            Ccli.Connect(8037);
            //Ccli.ConnectAndReceives(8037);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fffffff}");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show(Ccli.CheckConnected() ? "已连接" : "未连接");
        }

        private class MyWirter : TextWriter
        {
            public override Encoding Encoding => Encoding.UTF8;
            public override void WriteLine(string? value)
            {
                MessageBox.Show(value);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Ccli.Disconnect();
        }
    }
}
